<?php
namespace Home\Controller;
use Think\Controller;

class UcinchargelogController extends  BaseController
{
	public function index(){
		
		$root = get_baseroot();
		
		$page = intval($GLOBALS['request']['page']);
		
		$user =  $GLOBALS['user_info'];
		$root['session_id'] = \es_session::id();
		$user_id  = intval($user['id']);
		if ($user_id >0){
            if($page==0)
                $page = 1;
            $limit = (($page-1)*app_conf("PAGE_SIZE")).",".app_conf("PAGE_SIZE");

            //AES_DECRYPT(u.real_name_encrypt,'".AES_DECRYPT_KEY."') as pRealName,
            $sql = "select fr.requestNo as pMerBillNo,u.idno_encrypt,fr.fee as pMerFee,
			AES_DECRYPT(u.idno_encrypt,'".AES_DECRYPT_KEY."') as idno_encrypt,
			u.user_name,fr.id,u.user_type,u.id as user_id,fr.description,
			FROM_UNIXTIME( fr.create_time, '%Y-%m-%d' ) as pTrdDate,
			fr.amt as pTrdAmt ,'1' as pChannelType ,
			case when feeMode ='PLATFORM' then 1 else 2 end as pIpsFeeType 
			from ".DB_PREFIX."fuioupay_recharge fr 
			left join ".DB_PREFIX."user u on fr.user_id = u.id 
			where fr.code ='0000' and fr.is_callback=1 and u.id= ".$user_id." order by fr.id desc";

            $list_count = $GLOBALS['db']->getOne("select count(*) from ".DB_PREFIX."fuioupay_recharge fr left join ".DB_PREFIX."user u on fr.user_id = u.id where  fr.code ='0000' and is_callback=1 and u.id= ".$user_id."    order by fr.id desc");
            $list = array();
            $list_temp = array();
            $bank = $GLOBALS['db']->getRow("select a.name,b.bankcard from ".DB_PREFIX."bank a left join ".DB_PREFIX."user_bank b on a.id=b.bank_id where b.user_id =  ".$user_id);
            $card = $bank['bankcard'];
            $card = substr($card, 0, 4)."********".substr($card, -4);
            $name = $bank['name'];


            if($list_count>0){
                $list = $GLOBALS['db']->getAll($sql);
                foreach ($list  as $k => $v) {

                    // 充值金额
                    $item['pTrdAmt'] =  empty($list[$k]['pTrdAmt'])?"":$list[$k]['pTrdAmt'];
                    // 手续费
                    $item['pMerFee'] =  empty($list[$k]['pMerFee'])?"":$list[$k]['pMerFee'];

                    // 银行名称
                    $item['card'] = $card;
                    $item['name'] = $name;
                    // 身份证
                    //$item['idno_encrypt'] =  empty($list[$k]['idno_encrypt'])?"":$list[$k]['idno_encrypt'];
                    // 处理时间
                    $item['pTrdDate'] =  empty($list[$k]['pTrdDate'])?"":$list[$k]['pTrdDate'];
                    // 处理结果
                    $item['description'] =  empty($list[$k]['description'])?"成功":$list[$k]['description'];
                    $list_temp[$k] = $item;
                }
            }

            $root['list'] = $list_temp;
            //$root['page'] = array("page"=>$page,"page_total"=>ceil($list_count/app_conf("PAGE_SIZE")),"page_size"=>app_conf("PAGE_SIZE"));
            $root['page'] = array("page"=>$page,"page_total"=>1,"page_size"=>app_conf("PAGE_SIZE"));
            $root['response_code'] = 1;
            $root['show_err'] ="查询成功";
		}else{
			$root['response_code'] = 0;
			$root['show_err'] ="未登录";
			$root['user_login_status'] = 0;
		}
		$root['program_title'] = "充值日志";
		//output($root);
        $root['act'] = CONTROLLER_NAME;
        $root['hide_back'] = 1 ;
        $this->assign('data',$root);
        $this->display();
	}
}
?>
